import java.util.ArrayList;
import java.util.Iterator;

class News{
    private String newId;
    private String newName;
    private String newPeo;

    public News(String newId, String newName, String newPeo) {
        this.newId = newId;
        this.newName = newName;
        this.newPeo = newPeo;
    }

    @Override
    public String toString() {
        return newName ;
    }

    public String getNewId() {
        return newId;
    }

    public void setNewId(String newId) {
        this.newId = newId;
    }

    public String getNewName() {
        return newName;
    }

    public void setNewName(String newName) {
        this.newName = newName;
    }

    public String getNewPeo() {
        return newPeo;
    }

    public void setNewPeo(String newPeo) {
        this.newPeo = newPeo;
    }
}
class Dog{
    private String name;
    private String brand;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public Dog(String name, String brand) {

        this.name = name;
        this.brand = brand;
    }

    @Override
    public String toString() {
        return  name + " \t" + brand ;
    }
}
public class Work {
    public static void t1(){
        ArrayList list = new ArrayList();
        list.add(new News("001","每日早报","刘备"));
        list.add(new News("002","每日午报","张飞"));
        list.add(new News("003","每日晚报","关羽"));
        System.out.println("新闻标题数目为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            News news = (News)list.get(i);
            System.out.println((i+1) + ":" +news.getNewName());
        }
    }
    public static void t2(){
        ArrayList list = new ArrayList();
        list.add(new Dog("欧欧","金毛"));
        list.add(new Dog("毛毛","泰迪"));
        list.add(new Dog("嘎嘎","中华帝王犬"));
        for (Object o : list) {
            System.out.println(o);
        }
        System.out.println("删除之前有" + list.size() + "条狗");
        //删除第二条狗
        list.remove(1);
        System.out.println("删除之后还有" + list.size() + "条狗");
        for (Object o : list) {
            System.out.println(o);
        }
        //查询是否还有欧欧的信息
        for (int i = 0; i < list.size(); i++) {
            Dog dog = (Dog)list.get(i);
            if (dog.getName().equals("欧欧")){
                System.out.println("集合中包含欧欧的信息");
                break;
            }else {
                System.out.println("它已经嗝屁了");
            }
        }
    }
    public static void t3(){
        ArrayList list = new ArrayList();
        list.add("呜呜");
        list.add("嘎嘎");
        list.add("嗷嗷");
        list.add("嘿嘿");
        list.add("哈哈");
        list.add("喵喵");
        list.add("嘤嘤");
        list.add("略略");
        list.add("嗯嗯");
        list.add("啊啊");
        list.add("(๑•̀ㅂ•́)و✧");
        System.out.println(list);
        //二号位插入讯方软件学院
        list.add(2,"讯方软件学院");
        System.out.println(list);
        //获得第五个元素
        Object o = list.get(5-1);
        System.out.println(o.toString());
        //删除第六个元素
        list.remove(6-1);
        System.out.println(list);
        //修改第七个元素
        list.set(7-1,"我是修改的元素");
        //迭代器
        Iterator iterator = list.iterator();
        while (iterator.hasNext()){
            System.out.print(iterator.next() + "\t");
        }
    }
    public static void main(String[] args) {
        t3();
    }
}
